package com.ccz.demo.mongo;


import com.mongodb.MongoClient;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.net.UnknownHostException;

public class TestMongoInsert {


    public static void main(String[] args) throws UnknownHostException {
//        MongoClient mongoClient = new MongoClient();
//        MongoClientOptions.Builder mongoBuilder = new MongoClientOptions.Builder();
//        mongoBuilder.maxWaitTime(1000 * 60 * 3);
//        mongoBuilder.connectTimeout(60 * 1000 * 3);
//        /*与数据库建立连接的timeout设置为1分钟mongoBuilder.minConnectionsPerHost(1);*/
//        MongoClientURI mongoClientURI = new MongoClientURI("mongodb://127.0.0.1:27017/test", mongoBuilder);
//        SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoClientURI);
//        MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
        MongoClient mongoClient = new MongoClient("127.0.0.1");
        MongoTemplate mongoTemplate = new MongoTemplate(mongoClient, "test");

        System.out.println(mongoTemplate.getDb());

        Man man = new Man("ccz1", 21, "man");
        mongoTemplate.insert(man, "man");

    }

}
